fn main() {
    println!("Hello, world!");
    let a = String::from("12");
    let b = &a[0..1];
    println!("{}", b);

}
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ListNode {
    pub val: i32,
    pub next: Option<Box<ListNode>>
}

impl ListNode {
    fn new(val: i32) -> Self {
        ListNode {
            next: None,
            val
        }
    }
}
// 链表反转
pub fn reverse_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
    let mut prev = None;
    let mut curr = head;
    while let Some(mut node) = curr.take() {
        let next = node.next;
        node.next = prev;
        prev = Some(node);
        curr = next;
    }
    prev
}
// 给你两个字符串 haystack 和 needle ，请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标（下标从 0 开始）。如果 needle 不是 haystack 的一部分，则返回  -1 。
pub fn str_str(haystack: String, needle: String) -> i32 {
    let ns = needle.len();
    let ts = haystack.len();
    for i in 0..ts {
        let end_index = i + ns;
        if end_index <= ts && haystack[i..end_index].to_string() == needle {
            return i as i32;
        }
    }
    -1
}
